package com.ys.tdm.service.code.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.ys.tdm.bean.code.DataBase;
import com.ys.tdm.dao.code.IDataBaseDao;
import com.ys.tdm.service.code.IDataBaseService;
import com.ys.tdm.util.PagerModel;
import com.ys.tdm.util.Query;
import com.ys.tdm.util.StringTools;




/**
 * 数据库链接信息Service实现
 * @author hhj
 * @date 2018-03-07 10:13:57
 */
@Service
public class DataBaseServiceImpl implements IDataBaseService {

	@Resource
	private IDataBaseDao dataBaseDao;

	@Override
	public DataBase getDataBaseById(String id) throws Exception {
		return StringUtils.isNotBlank(id) ? this.dataBaseDao.getDataBaseById(id.trim()) : null;
	}

	@Override
	public List<DataBase> getDataBaseByIds(String ids) throws Exception {
		ids = StringTools.converString(ids);
		return StringUtils.isNotBlank(ids) ? this.dataBaseDao.getDataBaseByIds(ids) : null;
	}
	
	@Override
	public List<DataBase> getDataBaseByIdsList(List<String> ids) throws Exception {
		return CollectionUtils.isNotEmpty(ids) ? this.dataBaseDao.getDataBaseByIdsList(ids) : null;
	}

	@Override
	public List<DataBase> getAll(DataBase dataBase) throws Exception {
		return null != dataBase ? this.dataBaseDao.getAll(dataBase) : null;
	}

	/*@Override
	public PagerModel<DataBase> getPagerModelByQuery(DataBase dataBase, Query query)
			throws Exception {
		return (null != dataBase && null != query) ? this.dataBaseDao.getPagerModelByQuery(dataBase, query) : null;
	}*/
	
	@Override
	public int getByPageCount(DataBase dataBase)throws Exception {
		return (null != dataBase) ? this.dataBaseDao.getByPageCount(dataBase) : 0;
	}

	@Override
	public void insertDataBase(DataBase dataBase) throws Exception {
		this.dataBaseDao.insertDataBase(dataBase);
	}
	
	@Override
	public void insertDataBaseBatch(List<DataBase> dataBases) throws Exception {
		this.dataBaseDao.insertDataBaseBatch(dataBases);
	}
	
	@Override
	public void delDataBaseById(String id) throws Exception {
		if (StringUtils.isNotBlank(id)) {
			this.dataBaseDao.delDataBaseById(id.trim());
		}
	}
	
	@Override
	public void delDataBaseByIds(String ids) throws Exception {
		ids = StringTools.converString(ids);
		if(StringUtils.isNotBlank(ids)){
			this.dataBaseDao.delDataBaseByIds(ids);
		}
	}
	
	@Override
	public void delDataBaseByIdsList(List<String> ids) throws Exception {
		if(CollectionUtils.isNotEmpty(ids)){
			this.dataBaseDao.delDataBaseByIdsList(ids);
		}
	}

	@Override
	public int updateDataBase(DataBase dataBase) throws Exception {
		return this.dataBaseDao.updateDataBase(dataBase);
	}
	
	@Override
	public int updateDataBaseByIds(String ids,DataBase dataBase) throws Exception {
		return this.dataBaseDao.updateDataBaseByIds(ids, dataBase);
	}
	
	@Override
	public int updateDataBaseByIdsList(List<String> ids,DataBase dataBase) throws Exception {
		return this.dataBaseDao.updateDataBaseByIdsList(ids, dataBase);
	}
	
	@Override
	public int updateDataBaseList(List<DataBase> dataBases) throws Exception {
		return this.dataBaseDao.updateDataBaseList(dataBases);
	}

	@Override
	public List<String> getAllDataBase() throws Exception {
		return this.dataBaseDao.getAllDataBase();
	}
	
	/***
	 * 将"1,2,3,4,5..."这种形式的字符串转成"'1','2','3','4'..."这种形式
	 * @param strs
	 * @return
	 
	private String converString(String strs) {
		if (StringUtils.isNotBlank(strs)) {
			String[] idStrs = strs.trim().split(",");
			if (null != idStrs && idStrs.length > 0) {
				StringBuffer sbf = new StringBuffer("");
				for (String str : idStrs) {
					if (StringUtils.isNotBlank(str)) {
						sbf.append("'").append(str.trim()).append("'").append(",");
					}
				}
				if (sbf.length() > 0) {
					sbf = sbf.deleteCharAt(sbf.length() - 1);
					return sbf.toString();
				}
			}
		}
		return "";
	}*/
	
	/***
	 * 将"1,2,3,4,5..."这种形式的字符串转成List<String> 集合
	 * 
	 * @param strs
	 * @return
	 
	private List<String> converStringToList(String strs) {
		if (StringUtils.isNotBlank(strs)) {
			String[] idStrs = strs.trim().split(",");
			if (null != idStrs && idStrs.length > 0) {
				List<String> strsList = new ArrayList<String>();
				for (String str : idStrs) {
					if (StringUtils.isNotBlank(str)) {
						strsList.add(str.trim());
					}
				}
				if (strsList.size() > 0) {
					return strsList;
				}
			}
		}
		return null;
	}
	*/
	
	//------------api------------
	
}

